﻿// <copyright file="PersistenceInvalidRectangleException.cs" company="Ecole Normale Supérieure">
// Released under GPLv2
// </copyright>
// <summary>Contains the exception returned when an invalid rectangle is given as input to a Persitence method </summary>

namespace Sqwarea.Persistence.Exceptions
{
    using System;
    using System.Drawing;
    using System.Runtime.Serialization;
    using System.Security.Permissions;

    /// <summary>
    /// Persistence exception : Invalid rectangle
    /// </summary>
    [Serializable]
    public class PersistenceInvalidRectangleException : PersistenceException
    {
        /// <summary>
        /// Initializes a new instance of the PersistenceInvalidRectangleException class
        /// </summary>
        /// <param name="rectangle">Id of the invalid rectangle</param>
        /// <param name="message">Exception message</param>
        public PersistenceInvalidRectangleException(Rectangle rectangle, string message)
            : base(message)
        {
            Rectangle = rectangle;
        }

        /// <summary>
        /// Initializes a new instance of the PersistenceInvalidRectangleException class
        /// </summary>
        /// <param name="message">Exception message</param>
        public PersistenceInvalidRectangleException(string message)
            : base(message)
        {
        }

        /// <summary>
        /// Initializes a new instance of the PersistenceInvalidRectangleException class
        /// </summary>
        public PersistenceInvalidRectangleException()
        {
        }

        /// <summary>
        /// Initializes a new instance of the PersistenceInvalidRectangleException class
        /// </summary>
        /// <param name="message">Exception message</param>
        /// <param name="ex">Parent exception</param>
        public PersistenceInvalidRectangleException(string message, Exception ex)
            : base(message, ex)
        {
        }

        /// <summary>
        /// Initializes a new instance of the PersistenceInvalidRectangleException class
        /// </summary>
        /// <param name="info">Serialization infos</param>
        /// <param name="context">Streaming context</param>
        protected PersistenceInvalidRectangleException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        /// <summary>
        /// Gets the invalid rectangle.
        /// </summary>
        public Rectangle Rectangle { get; private set; }

        /// <summary>
        /// Gets object data
        /// </summary>
        /// <param name="info">Serialization info</param>
        /// <param name="context">Streaming context</param>
        [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
            info.AddValue("Rectangle", Rectangle);
        }
    }
}